const { sqlite3 } = require('../../mysql')

// 获取用户地址数据
async function ajaxuser(ctx) {
  console.log(ctx.request.body)
  const methodType = ctx.request.body.method

  if (methodType == 'usermessagecount') {
    ctx.body = {
      result: 'false',
      scode: '400001',
      ecode: '40101',
      infor: 'token获取失败',
      tips: 'HTTP_AUTHORIZATIO',
      table: '',
      version: '1.0',
      time: '2021-10-14 17:00:28',
      timestamp: '1634202028535R1964253078',
      FLY_FIELD_FILE_INFOR:
        '/server/c/access/ajaxuser.php::RBACTokenJudge:137,/server/fly/class/ClassRBAC.php::JsonInforFalse:99,/server/fly/fly/FlyJson.php:FlyJson:JsonModelInfor:867',
      FLY_FIELD_INFOR_EXTEND: '',
      code: '',
    }
  } else if (methodType == 'goodstype') {
    ctx.body = {
      result: 'true',
      code: '',
      fcode: '00031',
      msg: '有记录',
      version: '1634204492735R3862954710',
      count: '6',
      data: [
        {
          id: '11',
          onlyKey: '1612511482551R8372596401',
          descript: '',
          indexNumber: '-1',
          updateTime: '2021-04-07 14:40:37',
          addTime: '2021-02-05 15:51:22',
          shelfState: 'true',
          state: 'STATE_NORMAL',
          typeName: '衣物',
          typeIcon:
            '//pphuishou.datapersons.com/server/static/image/3000/1617777634697R8526017493.png',
          typeIndex: '10',
        },
        {
          id: '10',
          onlyKey: '1612511381495R8543271096',
          descript: '',
          indexNumber: '-1',
          updateTime: '2021-04-07 14:40:45',
          addTime: '2021-02-05 15:49:41',
          shelfState: 'true',
          state: 'STATE_NORMAL',
          typeName: '纸壳',
          typeIcon:
            '//pphuishou.datapersons.com/server/static/image/3000/1617777644217R6480352791.png',
          typeIndex: '12',
        },
        {
          id: '14',
          onlyKey: '1612511772319R9150647328',
          descript: '',
          indexNumber: '-1',
          updateTime: '2021-04-07 14:41:08',
          addTime: '2021-02-05 15:56:12',
          shelfState: 'true',
          state: 'STATE_NORMAL',
          typeName: '金属',
          typeIcon:
            '//pphuishou.datapersons.com/server/static/image/3000/1617777668134R3875920164.png',
          typeIndex: '13',
        },
        {
          id: '12',
          onlyKey: '1612511586247R0567831429',
          descript: '',
          indexNumber: '-1',
          updateTime: '2021-04-07 14:40:52',
          addTime: '2021-02-05 15:53:06',
          shelfState: 'true',
          state: 'STATE_NORMAL',
          typeName: '家电',
          typeIcon:
            '//pphuishou.datapersons.com/server/static/image/1000/1614391294979R3620189754.png',
          typeIndex: '14',
        },
        {
          id: '13',
          onlyKey: '1612511700141R0952146783',
          descript: '',
          indexNumber: '-1',
          updateTime: '2021-04-07 14:41:01',
          addTime: '2021-02-05 15:55:00',
          shelfState: 'true',
          state: 'STATE_NORMAL',
          typeName: '塑料',
          typeIcon:
            '//pphuishou.datapersons.com/server/static/image/3000/1617777660816R0564398217.png',
          typeIndex: '15',
        },
        {
          id: '15',
          onlyKey: '1612511821784R2186047395',
          descript: '',
          indexNumber: '-1',
          updateTime: '2021-04-07 14:41:16',
          addTime: '2021-02-05 15:57:01',
          shelfState: 'true',
          state: 'STATE_NORMAL',
          typeName: '其他',
          typeIcon:
            '//pphuishou.datapersons.com/server/static/image/3000/1617777675748R6318097245.png',
          typeIndex: '16',
        },
      ],
      infor: '有记录',
      tips: 'pp_goods_type',
      FLY_FIELD_INFOR_EXTEND: '',
    }
  }

  // const openId = ctx.query.openId
  // const addressData = await sqlite3('address').where({
  //   user_id: openId
  // })
  // console.log(addressData)
  // if (addressData.length != 0) {
  //   ctx.body = {
  //     addressData
  //   }
  // } else {
  //   ctx.body = false
  // }
}

module.exports = { ajaxuser }
